package com.mall.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.mall.common.utils.Response;
import com.mall.common.utils.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.mall.entity.SpuImages;
import com.mall.service.SpuImagesService;
import com.mall.common.utils.PageUtils;
import com.mall.common.utils.R;



/**
 * sku图片
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-08-24 16:47:36
 */
@RestController
@RequestMapping("product/spuimages")
public class SpuImagesController {
    @Autowired
    private SpuImagesService spuImagesService;



    @GetMapping("/list/{id}")
    public Response listSpuImages(@PathVariable("id") Integer id){
        List<SpuImages> spuImages = spuImagesService.listImages(id);
        Response response=null;
        if (spuImages != null){
            response = new Response(ResponseMessage.SUCCESS).data(spuImages);
        }else {
            response = new Response(ResponseMessage.ERROR);
        }
        return response;
    }
















    /**
     * 列表
     */
//    @RequestMapping("/list")
//  //  @RequiresPermissions("product:spuimages:list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = spuImagesService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("product:spuimages:info")
    public R info(@PathVariable("id") Long id){
        SpuImages spuImages = spuImagesService.getById(id);

        return R.ok().put("spuImages", spuImages);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("product:spuimages:save")
    public R save(@RequestBody SpuImages spuImages){
        spuImagesService.save(spuImages);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("product:spuimages:update")
    public R update(@RequestBody SpuImages spuImages){
        spuImagesService.updateById(spuImages);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //   @RequiresPermissions("product:spuimages:delete")
    public R delete(@RequestBody Long[] ids){
        spuImagesService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
